package org.abc.fund.service.funds;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

/**
 * 定时预热标签聚类结果，减少首次请求的冷启动开销
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class TagClusterWarmupScheduler {

    private final TagClusterService tagClusterService;

    @Value("${tag.cluster.scheduler.enabled:true}")
    private boolean schedulerEnabled;

    /**
     * 定时执行聚类预热任务
     */
    @Scheduled(cron = "${tag.cluster.scheduler.cron:0 15 * * * ?}")
    public void warmupClusters() {
        if (!schedulerEnabled) {
            return;
        }
        try {
            tagClusterService.getAllClusters();
            log.debug("标签聚类预热完成");
        } catch (Exception ex) {
            log.warn("标签聚类预热失败：{}", ex.getMessage(), ex);
        }
    }
}









